﻿package com.gamemeal.geom{
	import flash.display.BitmapData;
	/**
	 * @author Colin
	 */
	public class FastPerlinNoise {
		private var ctx:BitmapData;
		private var length:Number=0;

		public function FastPerlinNoise(baseX : Number, baseY : Number, numOctaves : uint, randomSeed : int, stitch : Boolean=false, fractalNoise : Boolean=true){
			ctx = new BitmapData(baseX,baseY,false);
			ctx.perlinNoise(baseX, baseY, numOctaves, randomSeed, stitch, fractalNoise,1,true);
			length = baseX*baseY;
		}

		public function getValueAt(position:int):Number{
			if(position>=length)position = position%length;
			return (ctx.getPixel(position%ctx.width, Math.floor(position/ctx.width))>>16)/255;
		}
	}
}
